package com.zyx.javademo.json;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zyx.javademo.bean.UserTel;

import java.util.List;

/**
 * @author Yaxi.Zhang
 * @since 2021/6/15 13:26
 * desc:
 */
public class JsonArrayDemo {
    public static void main(String[] args) {
        String jsonStr = "{\n" +
                "    \"data\": [{\n" +
                "            \"id\": \"1\",\n" +
                "            \"name\": \"lisi\",\n" +
                "            \"tel\": \"13838389438\"\n" +
                "        },\n" +
                "        {\n" +
                "            \"id\": \"2\",\n" +
                "            \"name\": \"wangwu\",\n" +
                "            \"tel\": \"18838389438\"\n" +
                "        }\n" +
                "    ],\n" +
                "    \"database\": \"gmall\",\n" +
                "    \"es\": 1598435650000,\n" +
                "    \"id\": 63,\n" +
                "    \"isDdl\": false\n" +
                "}";
        JSONObject jsonObject = JSONObject.parseObject(jsonStr);
        JSONArray jsonArray = jsonObject.getJSONArray("data");
        List<UserTel> userTels = jsonArray.toJavaList(UserTel.class);
        for (UserTel userTel : userTels) {
            System.out.println(userTel);
        }
    }
}
